<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">上级资源</label>
                <div class="layui-input-block">
                    <select name="parent_id" lay-search>
                        <option value="0">顶级资源</option>
                        <{foreach from=$all_rights item=item}>
                        <option value="<{$item.id}>"
                        <{if $parent_id and $parent_id eq $item.id}>selected<{/if}>
                        <{if isset($data) and $item.id eq $data->parent_id}>selected<{/if}>><{$item.name}></option>
                        <{/foreach}>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">资源组名</label>
                <div class="layui-input-block">
                    <input type="text" name="rightName" value="<{if isset($data)}><{$data->name}><{/if}>"
                           lay-verify="required" placeholder="eg. 用户删除" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-card">
                <div class="layui-card-header">选择权限资源</div>
                <div class="layui-card-body">
                    <div class="layui-tab">
                        <ul class="layui-tab-title">
                            <{foreach $all_actions as $mod=>$module}>
                            <{if $module}>
                            <li class="<{if $module@first }>layui-this<{/if}>"> <{$mod}></li>
                            <{/if}>
                            <{/foreach}>
                        </ul>
                        <div class="layui-tab-content">
                            <{foreach $all_actions as $mod=>$module}>
                            <{if $module}>
                            <div class="layui-tab-item <{if  $module@first }>layui-show<{/if}>">
                                <{foreach from=$module item=controller key=con}>
                                <div class="layui-form-item" pane="">
                                    <label class="layui-form-label"><{$con}></label>
                                    <div class="layui-input-block">
                                        <{foreach from=$controller item=act}>
                                        <input type="checkbox" name="actionList[]"
                                        <{if in_array(strtolower("$mod@$con@$act"),$allowList)}>checked="checked"<{/if}>
                                        value="<{$mod}>@<{$con}>@<{$act}>"
                                        lay-skin="primary" title="<{$mod}>/<{$con}>/<{$act}>" />
                                        <{/foreach}>
                                    </div>
                                </div>
                                <{/foreach}>
                            </div>
                            <{/if}>
                            <{/foreach}>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <input type="button" lay-submit lay-filter="form-submit" id="form-submit" value="确认">
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    layui.use(['form'], function () {
        var $ = layui.$
            , form = layui.form;
        form.render();
        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
        //监听提交
        form.on('submit(form-submit)', function (data) {
            var field = data.field; //获取提交的字段

            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //$.ajax({});
            $.post('/<{$module}>/<{$controller}>/<{$action}>/id/<{if isset($data)}><{$data->id}><{/if}>?isajax=1&', field, function (res) {
                if (res.code == 0) {
                    //ok
                    layui.table.reload('table-page'); //重载表格
                    layer.close(parentIndex); //再执行关闭
                } else {
                    layer.msg(res.msg);
                }
            }, 'json')
        });
    })
</script>